#include <QDebug>
#include <QDebug>
#include <QPluginLoader>
#include "QCoreApplication"

#include "uniontecsystemdll.h"
#include "uniontecsystemdll_global.h"
#include "WorkThreadManage/BackTcpThreadManage.h"
#include "WorkThreadManage/Hmiremotethreadmanage.h"

UnionTecSystemDLL::UnionTecSystemDLL(){
    this->UnionPcWorkThreadInit();
    this->UnionMainWindowInit();
    this->UnionThreadTieup();
    this->UnionSystemDLLStart();
}

UnionTecSystemDLL::~UnionTecSystemDLL(){
    this->UnionSystemQuite();
}

short UnionTecSystemDLL::UnionPcWorkThreadInit(){
    this->pBackTcpThread = new BackTcpThread();
    this->pBackUdpThread = new BackUdpThread();
    return NOERROR;
}

short UnionTecSystemDLL::UnionPcWokrThreadRelease(){
    delete pBackTcpThread;
    delete pBackUdpThread;
    return NOERROR;
}

short UnionTecSystemDLL::UnionMainWindowInit(){
    this->pHmiThread = new HmiLocalThread();
    this->pRemoteThread = new HmiRemoteThread();
    return NOERROR;
}

short UnionTecSystemDLL::UnionThreadTieup(){
    pHmiThread->pBackTcpThread = this->pBackTcpThread;
    pHmiThread->pBackUdpThread = this->pBackUdpThread;
    pRemoteThread->pBackTcpThread = this->pBackTcpThread;
    pRemoteThread->pBackUdpThread = this->pBackUdpThread;
    pRemoteThread->pHmiThread = this->pHmiThread;
    return NOERROR;
}

short UnionTecSystemDLL::UnionMainWindowRelease(){
    delete pHmiThread;
    delete pRemoteThread;
    return NOERROR;
}

short UnionTecSystemDLL::UnionSystemDLLStart(){
    this->pBackTcpThread->start(QThread::TimeCriticalPriority);
    this->pBackUdpThread->start(QThread::TimeCriticalPriority);
    return NOERROR;
}

short UnionTecSystemDLL::UnionMainWindowWriteProgressBar(int value){
    this->pHmiThread->WriteProgressBar(value);
    return NOERROR;
}

short UnionTecSystemDLL::UnionMainWindowWriteMessageBox(MessageType Type,const QString Data){
    this->pHmiThread->WriteMessageBox(Type,Data);
    return NOERROR;
}

short UnionTecSystemDLL::ReadUnionMainThreadLoopTime(double& value){
    value = this->pBackTcpThread->GetThreadLoopTime();
    return NOERROR;
}

short UnionTecSystemDLL::UnionDebugWindowShow(){
    this->pHmiThread->show();
    return NOERROR;
}

short UnionTecSystemDLL::UnionAdminWindowShow(){
    this->pHmiThread->Adminshow();
    return NOERROR;
}

short UnionTecSystemDLL::UnionDebugWindowHide(){
    this->pHmiThread->hide();
    return NOERROR;
}

short UnionTecSystemDLL::UnionSystemQuite(){
    this->UnionPcWokrThreadRelease();
    this->UnionMainWindowRelease();
    return NOERROR;
}
